package com.dz.finance.api.controller;

import com.dz.finance.wechat.aes.AesException;
import com.dz.finance.wechat.dto.MpCommonReq;
import com.dz.finance.wechat.service.WechatEventService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author: DengHaoQi
 * @date: 2024/6/6 16:45
 * @description: 微信模块
 */


@Slf4j
@Api("微信模块")
@RestController
@RequestMapping("/wxEvent")
@RequiredArgsConstructor
public class WechatEventController {

    private final WechatEventService wechatEventService;

    @ApiOperation("接收微信推送事件")
    @RequestMapping(value = "/receiveMpEvent",method = {RequestMethod.GET,RequestMethod.POST})
    public String receiveMpEvent(@Validated @ModelAttribute MpCommonReq mpCommonReq, HttpServletRequest httpServletRequest) throws AesException, IOException {
        log.info("微信调用接口请求方式:{}",httpServletRequest.getMethod());
        return wechatEventService.receiveMpEvent(mpCommonReq,httpServletRequest);
    }
}
